


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
  <title>Coverage Report :: ViennaEntityManager</title>
  <style type="text/css">
    @import "../../.css/coverage.css";
  </style>
</head>

<body>
<div class="header"></div>

<div class="content">
<div class="breadCrumbs">
    [ <a href="../../index.html">all classes</a> ]
    [ <a href="../index.html">at.schauer.gregor.vienna.jpa</a> ]
</div>

<h1>Coverage Summary for Class: ViennaEntityManager (at.schauer.gregor.vienna.jpa)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">ViennaEntityManager</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/ 1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/ 27)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/ 56)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<div class="sourceCode"><i>1</i>&nbsp;/*
<i>2</i>&nbsp; * Copyright 2012 Gregor Schauer
<i>3</i>&nbsp; *
<i>4</i>&nbsp; * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<i>5</i>&nbsp; * you may not use this file except in compliance with the License.
<i>6</i>&nbsp; * You may obtain a copy of the License at
<i>7</i>&nbsp; *
<i>8</i>&nbsp; *      http://www.apache.org/licenses/LICENSE-2.0
<i>9</i>&nbsp; *
<i>10</i>&nbsp; * Unless required by applicable law or agreed to in writing, software
<i>11</i>&nbsp; * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<i>12</i>&nbsp; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<i>13</i>&nbsp; * See the License for the specific language governing permissions and
<i>14</i>&nbsp; * limitations under the License.
<i>15</i>&nbsp; */
<i>16</i>&nbsp;package at.schauer.gregor.vienna.jpa;
<i>17</i>&nbsp;
<i>18</i>&nbsp;import at.schauer.gregor.vienna.context.ViennaContext;
<i>19</i>&nbsp;import at.schauer.gregor.vienna.datastore.DataStore;
<i>20</i>&nbsp;import at.schauer.gregor.vienna.exception.ViennaException;
<i>21</i>&nbsp;import org.apache.commons.beanutils.BeanUtils;
<i>22</i>&nbsp;import org.springframework.util.ReflectionUtils;
<i>23</i>&nbsp;
<i>24</i>&nbsp;import javax.persistence.*;
<i>25</i>&nbsp;import java.lang.reflect.Method;
<i>26</i>&nbsp;import java.util.Arrays;
<i>27</i>&nbsp;
<i>28</i>&nbsp;/**
<i>29</i>&nbsp; * @author Gregor Schauer
<i>30</i>&nbsp; */
<i>31</i>&nbsp;public class ViennaEntityManager implements EntityManager {
<b class="nc"><i>32</i>&nbsp;	private final String ALREADY_CLOSED = this.getClass().getName() + &quot; is already closed&quot;;</b>
<b class="nc"><i>33</i>&nbsp;	private FlushModeType flushMode = FlushModeType.AUTO;</b>
<b class="nc"><i>34</i>&nbsp;	private boolean open = true;</b>
<i>35</i>&nbsp;	private ViennaContext ctx;
<i>36</i>&nbsp;
<b class="nc"><i>37</i>&nbsp;	public ViennaEntityManager(ViennaContext ctx) {</b>
<b class="nc"><i>38</i>&nbsp;		this.ctx = ctx;</b>
<i>39</i>&nbsp;	}
<i>40</i>&nbsp;
<i>41</i>&nbsp;	@Override
<i>42</i>&nbsp;	public void persist(Object entity) {
<b class="nc"><i>43</i>&nbsp;		merge(entity);</b>
<i>44</i>&nbsp;	}
<i>45</i>&nbsp;
<i>46</i>&nbsp;	@Override
<i>47</i>&nbsp;	@SuppressWarnings(&quot;unchecked&quot;)
<i>48</i>&nbsp;	public &lt;T&gt; T merge(T entity) {
<b class="nc"><i>49</i>&nbsp;		checkAccess();</b>
<b class="nc"><i>50</i>&nbsp;		ctx.getDataStore((Class&lt;T&gt;) entity.getClass()).save(entity);</b>
<b class="nc"><i>51</i>&nbsp;		return entity;</b>
<i>52</i>&nbsp;	}
<i>53</i>&nbsp;
<i>54</i>&nbsp;	@Override
<i>55</i>&nbsp;	@SuppressWarnings(&quot;unchecked&quot;)
<i>56</i>&nbsp;	public void remove(Object entity) {
<b class="nc"><i>57</i>&nbsp;		checkAccess();</b>
<b class="nc"><i>58</i>&nbsp;		DataStore dataStore = ctx.getDataStore(entity.getClass());</b>
<b class="nc"><i>59</i>&nbsp;		dataStore.delete(entity);</b>
<i>60</i>&nbsp;	}
<i>61</i>&nbsp;
<i>62</i>&nbsp;	@Override
<i>63</i>&nbsp;	public &lt;T&gt; T find(Class&lt;T&gt; entityClass, Object primaryKey) {
<b class="nc"><i>64</i>&nbsp;		checkAccess();</b>
<b class="nc"><i>65</i>&nbsp;		return ctx.getDataStore(entityClass).load(entityClass, primaryKey);</b>
<i>66</i>&nbsp;	}
<i>67</i>&nbsp;
<i>68</i>&nbsp;	@Override
<i>69</i>&nbsp;	public &lt;T&gt; T getReference(Class&lt;T&gt; entityClass, Object primaryKey) {
<b class="nc"><i>70</i>&nbsp;		T t = find(entityClass, primaryKey);</b>
<b class="nc"><i>71</i>&nbsp;		if (t == null) {</b>
<b class="nc"><i>72</i>&nbsp;			throw new EntityNotFoundException(entityClass.getName() + &quot; with id &quot; + primaryKey);</b>
<i>73</i>&nbsp;		}
<b class="nc"><i>74</i>&nbsp;		return t;</b>
<i>75</i>&nbsp;	}
<i>76</i>&nbsp;
<i>77</i>&nbsp;	@Override
<i>78</i>&nbsp;	public void flush() {
<b class="nc"><i>79</i>&nbsp;		checkAccess();</b>
<i>80</i>&nbsp;	}
<i>81</i>&nbsp;
<i>82</i>&nbsp;	@Override
<i>83</i>&nbsp;	public void setFlushMode(FlushModeType flushMode) {
<b class="nc"><i>84</i>&nbsp;		this.flushMode = flushMode;</b>
<i>85</i>&nbsp;	}
<i>86</i>&nbsp;
<i>87</i>&nbsp;	@Override
<i>88</i>&nbsp;	public FlushModeType getFlushMode() {
<b class="nc"><i>89</i>&nbsp;		return flushMode;</b>
<i>90</i>&nbsp;	}
<i>91</i>&nbsp;
<i>92</i>&nbsp;	@Override
<i>93</i>&nbsp;	public void lock(Object entity, LockModeType lockMode) {
<b class="nc"><i>94</i>&nbsp;		throw new IllegalStateException(_getMethodSignature() + &quot; not supported&quot;);</b>
<i>95</i>&nbsp;	}
<i>96</i>&nbsp;
<i>97</i>&nbsp;	@Override
<i>98</i>&nbsp;	@SuppressWarnings(&quot;unchecked&quot;)
<i>99</i>&nbsp;	public void refresh(Object entity) {
<b class="nc"><i>100</i>&nbsp;		Class clazz = entity.getClass();</b>
<b class="nc"><i>101</i>&nbsp;		Object load = ctx.getDataStore(clazz).load(clazz, ctx.getMetadataProvider(clazz).getIdentifier(entity));</b>
<b class="nc"><i>102</i>&nbsp;		if (load == null) {</b>
<i>103</i>&nbsp;			return;
<i>104</i>&nbsp;		}
<i>105</i>&nbsp;
<i>106</i>&nbsp;		try {
<b class="nc"><i>107</i>&nbsp;			BeanUtils.copyProperties(entity, load);</b>
<b class="nc"><i>108</i>&nbsp;		} catch (Exception e) {</b>
<b class="nc"><i>109</i>&nbsp;			throw new RuntimeException(e);</b>
<b class="nc"><i>110</i>&nbsp;		}</b>
<i>111</i>&nbsp;	}
<i>112</i>&nbsp;
<i>113</i>&nbsp;	@Override
<i>114</i>&nbsp;	public void clear() {
<b class="nc"><i>115</i>&nbsp;		checkAccess();</b>
<i>116</i>&nbsp;	}
<i>117</i>&nbsp;
<i>118</i>&nbsp;	@Override
<i>119</i>&nbsp;	@SuppressWarnings(&quot;unchecked&quot;)
<i>120</i>&nbsp;	public boolean contains(Object entity) {
<b class="nc"><i>121</i>&nbsp;		checkAccess();</b>
<b class="nc"><i>122</i>&nbsp;		Class clazz = entity.getClass();</b>
<b class="nc"><i>123</i>&nbsp;		return ctx.getDataStore(clazz).load(clazz, ctx.getMetadataProvider(clazz).getIdentifier(entity)) != null;</b>
<i>124</i>&nbsp;	}
<i>125</i>&nbsp;
<i>126</i>&nbsp;	@Override
<i>127</i>&nbsp;	public Query createQuery(String qlString) {
<b class="nc"><i>128</i>&nbsp;		throw new IllegalStateException(_getMethodSignature() + &quot; not supported&quot;);</b>
<i>129</i>&nbsp;	}
<i>130</i>&nbsp;
<i>131</i>&nbsp;	@Override
<i>132</i>&nbsp;	public Query createNamedQuery(String name) {
<b class="nc"><i>133</i>&nbsp;		throw new IllegalStateException(_getMethodSignature() + &quot; not supported&quot;);</b>
<i>134</i>&nbsp;	}
<i>135</i>&nbsp;
<i>136</i>&nbsp;	@Override
<i>137</i>&nbsp;	public Query createNativeQuery(String sqlString) {
<b class="nc"><i>138</i>&nbsp;		throw new IllegalStateException(_getMethodSignature() + &quot; not supported&quot;);</b>
<i>139</i>&nbsp;	}
<i>140</i>&nbsp;
<i>141</i>&nbsp;	@Override
<i>142</i>&nbsp;	public Query createNativeQuery(String sqlString, Class resultClass) {
<b class="nc"><i>143</i>&nbsp;		throw new IllegalStateException(_getMethodSignature() + &quot; not supported&quot;);</b>
<i>144</i>&nbsp;	}
<i>145</i>&nbsp;
<i>146</i>&nbsp;	@Override
<i>147</i>&nbsp;	public Query createNativeQuery(String sqlString, String resultSetMapping) {
<b class="nc"><i>148</i>&nbsp;		throw new IllegalStateException(_getMethodSignature() + &quot; not supported&quot;);</b>
<i>149</i>&nbsp;	}
<i>150</i>&nbsp;
<i>151</i>&nbsp;	@Override
<i>152</i>&nbsp;	public void joinTransaction() {
<b class="nc"><i>153</i>&nbsp;		throw new IllegalStateException(_getMethodSignature() + &quot; not supported&quot;);</b>
<i>154</i>&nbsp;	}
<i>155</i>&nbsp;
<i>156</i>&nbsp;	@Override
<i>157</i>&nbsp;	public Object getDelegate() {
<b class="nc"><i>158</i>&nbsp;		return null;</b>
<i>159</i>&nbsp;	}
<i>160</i>&nbsp;
<i>161</i>&nbsp;	@Override
<i>162</i>&nbsp;	public void close() {
<b class="nc"><i>163</i>&nbsp;		this.open = false;</b>
<i>164</i>&nbsp;	}
<i>165</i>&nbsp;
<i>166</i>&nbsp;	@Override
<i>167</i>&nbsp;	public boolean isOpen() {
<b class="nc"><i>168</i>&nbsp;		return open;</b>
<i>169</i>&nbsp;	}
<i>170</i>&nbsp;
<i>171</i>&nbsp;	@Override
<i>172</i>&nbsp;	public EntityTransaction getTransaction() {
<b class="nc"><i>173</i>&nbsp;		throw new IllegalStateException(_getMethodSignature() + &quot; not supported&quot;);</b>
<i>174</i>&nbsp;	}
<i>175</i>&nbsp;
<i>176</i>&nbsp;	protected void checkAccess() {
<b class="nc"><i>177</i>&nbsp;		if (!open) {</b>
<b class="nc"><i>178</i>&nbsp;			throw new IllegalStateException(ALREADY_CLOSED);</b>
<i>179</i>&nbsp;		}
<i>180</i>&nbsp;	}
<i>181</i>&nbsp;
<i>182</i>&nbsp;	protected String _getMethodName() {
<b class="nc"><i>183</i>&nbsp;		StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();</b>
<b class="nc"><i>184</i>&nbsp;		for (StackTraceElement element : stackTraceElements) {</b>
<b class="nc"><i>185</i>&nbsp;			if (element.getMethodName().charAt(0) != &#39;_&#39;) {</b>
<b class="nc"><i>186</i>&nbsp;				return element.getMethodName();</b>
<i>187</i>&nbsp;			}
<i>188</i>&nbsp;		}
<b class="nc"><i>189</i>&nbsp;		throw new ViennaException();</b>
<i>190</i>&nbsp;	}
<i>191</i>&nbsp;
<i>192</i>&nbsp;	protected Method _getMethod() {
<b class="nc"><i>193</i>&nbsp;		String name = _getMethodName();</b>
<b class="nc"><i>194</i>&nbsp;		return ReflectionUtils.findMethod(this.getClass(), name);</b>
<i>195</i>&nbsp;	}
<i>196</i>&nbsp;
<i>197</i>&nbsp;	protected String _getMethodSignature() {
<b class="nc"><i>198</i>&nbsp;		Method method = _getMethod();</b>
<b class="nc"><i>199</i>&nbsp;		String parameters = Arrays.toString(method.getParameterTypes());</b>
<b class="nc"><i>200</i>&nbsp;		parameters = parameters.substring(1, parameters.length() - 1);</b>
<b class="nc"><i>201</i>&nbsp;		return String.format(&quot;%s.%s(%s)&quot;, this.getClass().getName(), method.getName(), parameters);</b>
<i>202</i>&nbsp;	}
<i>203</i>&nbsp;}
</div>
</div>

<div class="footer">
    
    <div style="float:right;">generated on 2012-07-17 20:23</div>
</div>
</body>
</html>
